/*
 * PlaceNameDialog.java
 *
 * Created on 26 maj 2007, 16:24
 */

package edu.uj.petri.commands;

import edu.uj.petri.document.Document;
import edu.uj.petri.model.Place;
import java.util.ResourceBundle;
import javax.swing.JOptionPane;

/**
 *
 * @author Paweł
 */
public class PlaceNameDialog extends Command {
    
    private Place place;
        
    /** Creates a new instance of PlaceNameDialog */
    public PlaceNameDialog( Place place ){
        super(true); // execute and forget - do not remember on command stack
        this.place = place;
    }

    public String toString() {
        
        return ""; // executeAndForget
    }

    void execute() {
        
        String oldName = place.getName();
        String newName = JOptionPane.showInputDialog( null, ResourceBundle.getBundle("edu/uj/petri/messages").getString("zmiana_nazwy_miejsca_prompt"), oldName);
        if (newName != null && !newName.equals(""))
        {
          Document.getActiveDocument().execute(new SetPlaceNameCommand( place, newName ));
        }
    }
    
     void undo() {
        throw new IllegalArgumentException(ResourceBundle.getBundle("edu/uj/petri/messages").getString("cannot_be_undone"));
    }

    boolean canBeCombined(Command c) {
        return false;
    }
    
    private static final long serialVersionUID = 2747492258596028969L;    
}
